package com.zxl.common.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.zxl.common.constant.DeleteStatusConstant;
import com.zxl.common.exception.BusinessException;
import com.zxl.common.mapper.SysInformationGroupMapper;
import com.zxl.common.model.bo.information.InformationGroupSaveBo;
import com.zxl.common.model.pojo.SysGoods;
import com.zxl.common.model.pojo.SysGoodsType;
import com.zxl.common.model.pojo.SysInformationGroup;
import com.zxl.common.model.query.information.InformationGroupQuery;
import com.zxl.common.service.SysInformationGroupService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zxw
 * @since 2023-04-24
 */
@Service
public class SysInformationGroupServiceImpl extends ServiceImpl<SysInformationGroupMapper, SysInformationGroup> implements SysInformationGroupService {
    @Resource
    private SysInformationGroupMapper sysInformationGroupMapper;

    @Override
    public void add(InformationGroupSaveBo bo) {
        SysInformationGroup entity = new SysInformationGroup();
        BeanUtil.copyProperties(bo, entity);
        sysInformationGroupMapper.insert(entity);
    }

    @Override
    public void update(InformationGroupSaveBo bo) {
        if(bo.getId() == null) {
            throw new BusinessException("请传入分类id");
        }
        SysInformationGroup entity = new SysInformationGroup();
        BeanUtil.copyProperties(bo, entity);
        sysInformationGroupMapper.updateById(entity);
    }

    @Override
    public List<SysInformationGroup> getList(InformationGroupQuery query) {
        PageHelper.startPage(query.getPageNumber(), query.getPageSize());
        List<SysInformationGroup> list = sysInformationGroupMapper.getList();
        return list;
    }

    @Override
    public void delete(Integer id) {
        if(id == null){
            throw new BusinessException("id不允许为空");
        }
        SysInformationGroup entity = new SysInformationGroup();
        entity.setId(id);
        entity.setDeleteStatus(DeleteStatusConstant.HAS_DELETE.getCode());
        sysInformationGroupMapper.updateById(entity);
    }
}
